package com.qf.dao;

import com.qf.pojo.entity.TbAccount;
import com.qf.pojo.entity.TbAdmin;
import com.qf.pojo.entity.TbUser;
import com.qf.pojo.request.TbAdminReq;
import com.sun.tracing.dtrace.ModuleAttributes;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.hibernate.collection.internal.PersistentIdentifierBag;

import java.util.List;

/**
 * @author xingyu
 */

@Mapper
public interface TbAdminMapper {


    @Select("select * from tb_admin")
    List<TbAdmin> findAll();

    @Insert("insert into tb_admin (adname) values (#{adName}) ")
    int insert(String adName);

    @Update("update tb_admin set adname=#{adName} where adid=#{adId}")
    int update(TbAdminReq tbAdminReq);

    @Delete("delete from tb_admin where adid=#{adId}")
    int del(Integer adId);


    @Delete("delete from tb_user where uid=#{uid}")
    int delUser(Integer uid);



    @Results(
            id="TbUserMap",value = {
            @Result(column = "uid",property = "uid"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "user_tel",property = "userTel"),
            @Result(column = "user_email",property = "userEmail"),
            @Result(column = "user_ID",property = "userId"),
            @Result(column = "user_address",property = "userAddress"),

            @Result(column ="uid",property ="accountList",
//                    javaType = TbAccount.class,
                    many = @Many(select = "com.qf.dao.AccountMapper.findByUid",fetchType = FetchType.EAGER)
//                    many = @Many(select = "com.qf.dao.AccountMapper.findByUid")

            )

    })
    @Select("select * from tb_user")
    List<TbUser> finAllUser();



    //    删除卡
    @Delete("delete from  tb_account where aid=#{aid}")
    int delAccount(Integer aid);
}
